#include "tree.h"
#define PARENT(i) (i / 2)
int heapMaximun(ARRAY *arr)
{
    return arr->int_array[0];
}

int heapExtractMax(ARRAY *arr)
{
    int max = arr->int_array[0];
    arr->int_array[0] = arr->int_array[arr->array_size - 1];
    arr->array_size--;
    Heapify(arr->int_array, arr->array_size, 0);
    return max;
}
int Heapify(int *arr, int size, int index)
{
    int largest = index;
    int left = 2 * index + 1;
    int right = 2 * index + 2;
    if (left < size && arr[left] > arr[largest])
    {
        largest = left;
    }

    if (right < size && arr[right] > arr[largest])
    {
        largest = right;
    }
    if (largest != index)
    {
        int key = arr[index];
        arr[index] = arr[largest];
        arr[largest] = key;
        Heapify(arr, size, index);
    }
    return 0;
}

int maxHeapInsert(ARRAY *A,int key){
    
}